package com.sls.game.parser.nutsnet;

import java.io.File;
import java.util.List;

import com.sls.game.pojo.NutsNetServerInfo;

/**
 * 
 * @description 坚果网络开放接口，请求访问url的拼装
 * @author Wangxuegang
 * @date 2012-9-4
 * 
 */
public class NutsNetAssembleHttpUrl {

	private static String serIp = null;

	private static String serPort = null;

	private static String serPath = null;

	/**
	 * 拼装http请求的url
	 * 
	 * @param paraStr
	 *            所传参数字符串拼接
	 * @return
	 */
	public static String assembleHttpUrl(String paraStr, String path) {
		String url = "";
		// 从xml配置文件中读取坚果网络服务ip和port
		List<NutsNetServerInfo> serverList = NutsNetServerSaxParseXml
				.parseXmlString("conf" + File.separator + "nutsNetServer.xml");
		if (serverList.size() > 0) {
			for (NutsNetServerInfo info : serverList) {
				serIp = info.getIp();
				serPort = info.getPort();
			}
		}

		StringBuffer strBuf = new StringBuffer();
		strBuf.append("http://");
		strBuf.append(serIp.trim());
		strBuf.append(":");
		strBuf.append(serPort.trim());
		strBuf.append("/");
		strBuf.append(path.trim()); // 端口号和？之间的内容
		strBuf.append("?");
		strBuf.append(paraStr.trim());
		url = strBuf.toString().trim();

		return url;
	}

	/**
	 * 获取xml配置文件中的值
	 */
	public static NutsNetServerInfo getKeyValue() {
		NutsNetServerInfo serverInfo = null;
		List<NutsNetServerInfo> serverList = NutsNetServerSaxParseXml
				.parseXmlString("conf" + File.separator + "nutsNetServer.xml");
		if (serverList.size() > 0) {
			for (int i = 0; i < serverList.size(); i++) {
				serverInfo = serverList.get(i);
			}
		}

		return serverInfo;
	}

	public static String getSerIp() {
		return serIp;
	}

	public static void setSerIp(String serIp) {
		NutsNetAssembleHttpUrl.serIp = serIp;
	}

	public static String getSerPort() {
		return serPort;
	}

	public static void setSerPort(String serPort) {
		NutsNetAssembleHttpUrl.serPort = serPort;
	}

	public static String getSerPath() {
		return serPath;
	}

	public static void setSerPath(String serPath) {
		NutsNetAssembleHttpUrl.serPath = serPath;
	}

}
